package org.cypress.rtpack.controller;
//处理rtpack_config这个表的控制器

import org.cypress.rtpack.common.core.Result;
import org.cypress.rtpack.entity.RtpackConfig;
import org.cypress.rtpack.service.IRtpackConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RestController
@RequestMapping("/rtpack_config")
public class RtpackConfigController {

    @Autowired
    private IRtpackConfigService rtpackConfigService;

    private static final Logger logger = LoggerFactory.getLogger(RtpackConfigController.class);

    @GetMapping("/by_key/{key}")
    public Result<RtpackConfig> getByKey(@PathVariable("key") String key) {
        RtpackConfig inst = rtpackConfigService.getByKey(key);
        return Result.dataOf(inst);
    }

    @GetMapping("/list")
    public Result<RtpackConfig> getList() {
        List<RtpackConfig> list = rtpackConfigService.getAll();
        return Result.dataOf(list);
    }

    @PutMapping("/updateByKey")
    public Result<RtpackConfig> updateConfig(@RequestBody RtpackConfig inst) {
        RtpackConfig updatedConfig = rtpackConfigService.updateByKey(inst);
        return Result.dataOf(updatedConfig);
    }

    @PutMapping("/batchUpdateByKey")
    public Result<List<RtpackConfig>> batchUpdate(@RequestBody List<RtpackConfig> configList) {
        List<RtpackConfig> updated = rtpackConfigService.batchUpdateByKey(configList);
        return Result.dataOf(updated);
    }
}
